﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Input;
using UITLibraryManagement.ModelValidators;
using System.Windows;

namespace UITLibraryManagement.ViewModel
{
    public class DocGiaViewModel : ViewModelBase, IDataErrorInfo
    {
        #region Fields
        readonly DocGiaValidator _this;
        readonly IDocGiaRepository _thisRepository;
        #endregion

        #region Constructor
        public DocGiaViewModel(DOCGIA docgia)
        {
            this._this = new DocGiaValidator(docgia);
            this._thisRepository = App.GetInstance<IDocGiaRepository>();
        }
        #endregion

        #region Command
        RelayCommand _saveCommand;
        RelayCommand _deleteCommand;
        public ICommand DeleteCommand
        {
            get
            {
                if (_deleteCommand == null)
                {
                    _deleteCommand = new RelayCommand(
                        param => this.Delete(),
                        param => this.CanDelete
                        );
                }
                return _deleteCommand;
            }
        }
        public ICommand SaveCommand
        {
            get
            {
                if (_saveCommand == null)
                {
                    _saveCommand = new RelayCommand(
                        param => this.Save(),
                        param => this.CanSave
                        );
                }
                return _saveCommand;
            }
        }
        public void Save()
        {
        }
        bool CanDelete { get { return true; } }
        public void Delete()
        {
            MessageBox.Show("Delete object"); 
        }
        bool CanSave
        {
            get { return _this.IsValid; } 
        }
        bool IsNewDocGia
        {
            get { return !_thisRepository.IsExist(_this); }
        }
        #endregion

        #region Presentation Proterties
        #endregion

        #region Properties
        public string MaDocGia
        {
            get { return _this.MaDocGia; }
            set
            {
                if (value == _this.MaDocGia)
                    return;

                _this.MaDocGia = value;
                base.OnPropertyChanged("MaDocGia");
            }
        }
        public string TenDocGia
        {
            get { return _this.TenDocGia; }
            set
            {
                if (value == _this.TenDocGia)
                    return;

                _this.TenDocGia = value;
                base.OnPropertyChanged("TenDocGia");
            }
        }
        public Nullable<System.DateTime> NgaySinh
        {
            get { return _this.NgaySinh; }
            set
            {
                if (value == _this.NgaySinh)
                    return;

                _this.NgaySinh = value;
                base.OnPropertyChanged("NgaySinh");
            }
        }
        public string DiaChi
        {
            get { return _this.DiaChi; }
            set
            {
                if (value == _this.DiaChi)
                    return;

                _this.DiaChi = value;
                base.OnPropertyChanged("DiaChi");
            }
        }
        public string MaTruong
        {
            get { return _this.MaTruong; }
            set
            {
                if (value == _this.MaTruong)
                    return;

                _this.MaTruong = value;
                base.OnPropertyChanged("MaTruong");
            }
        }
        public string SoCMND
        {
            get { return _this.SoCMND; }
            set
            {
                if (value == _this.SoCMND)
                    return;

                _this.SoCMND = value;
                base.OnPropertyChanged("SoCMND");
            }
        }
        public string DienThoai
        {
            get { return _this.DienThoai; }
            set
            {
                if (value == _this.DienThoai)
                    return;

                _this.DienThoai = value;
                base.OnPropertyChanged("DienThoai");
            }
        }
        public string MaLoaiDocGia
        {
            get { return _this.MaLoaiDocGia; }
            set
            {
                if (value == _this.MaLoaiDocGia)
                    return;

                _this.MaLoaiDocGia = value;
                base.OnPropertyChanged("MaLoaiDocGia");
            }
        }
        #endregion

        #region IDataErrorInfo Members
        string IDataErrorInfo.Error
        {
            get { return (_this as IDataErrorInfo).Error; }
        }

        string IDataErrorInfo.this[string columnName]
        {
            get {
                string error = null;
                error = (_this as IDataErrorInfo)[columnName];

                return error;
            }
        }
        #endregion // IDataErrorInfo Members



    }
}
